<?php
require 'Model.php';
class indexModel extends Model{
	function __Construct(){
		parent::__Construct();
	}
	//获取视频类别列表
	function getclasstype(){
		$sql="select * from coursetype ";
		$ft_list = $this->conn->query($sql);
		return $ft_list;
	}
	function getcourse($id){
		$sql="select * from courses where cid='$id'";
		$t_list=$this->conn->query($sql);
		return $t_list;
	}
	function getallcourse()
	{
		$sql="select * from courses";
		$t_list=$this->conn->query($sql);
		return $t_list;
	}
	function getidteacher($id){
		$sql="select * from courses where cid='$id'";
		$t_show=$this->conn->query($sql);
		return $t_show;
	}

	function getclass($id){
		$sql="select * from courses where ctid='$id'";
		$c_lists=$this->conn->query($sql);
		return $c_lists;
	}
	function getnotice(){
		$sql="select * from notice ";
		$n_list=$this->conn->query($sql);
		return $n_list;
	}
	function getchoose($cid){
		$uid='12';
		//$sql="select * from courses where cid='$id1'";
		$sql="insert into choose values(null,$cid,$uid)";

		$data=$this->conn->query($sql);
		return $data;

	}
	function getchooselist(){
	$sql='select choose.uid,choose.id,user.username,courses.coursename,courses.teacher from user
	right join choose on user.uid=choose.uid left join courses on choose.cid=courses.cid where user.uid=12 ';
	$data=$this->conn->query($sql);
	return  $data;

	}
	function getdelchoose($id){
		$sql= "Delete from choose where id=".$id;
			$data=$this->conn->query($sql);
			return  $data;


	}

	function doLogin(){
		if($_POST["id"]==0) {
			$u=$_POST["name"];
			$p=$_POST["password"];
			$sql="select * from user where username='$u' and password='$p'";
			$rs=mysql_query($sql);
			if($rs) {
				session_start();
				$_SESSION["user"]=$u;
				header("location:index.php");
			} else {
				header("location:index.php?re=1&msg=登录失败，请重新登录");
			}
		} else {
			//如果是内容页登录
			$id=$_POST["id"];
			$u=$_POST["name"];
			$p=$_POST["password"];
			$sql="select * from user where name='$u' and password='$p'";
			$rs=mysql_query($sql)or die('查询失败！'.mysql_error());
			$num=mysql_num_rows($rs);
			if($num>0) {
				session_start();
				$_SESSION["user"]=$u;
				header("location:show.php?id=$id");
			}
			else{
				header("location:show.php?re=1&msg=登录失败，请重新登录&vid=$vid");
			}
		}
	}
}
?>
